package cn.zsc.netdisk.common;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 获取当前登录的用户账号
 * @author ccying
 * @date 2021/2/20
 */
public class UserInfo {
    /**
     * @return 当前登录的用户账号
     * */
    public static String getPrincipal() {
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        return (String) authentication.getPrincipal();
    }
}
